import { DataTypes, Model } from 'sequelize'
import { sequelize } from './index'

export class Room extends Model {
  public id!: number
  public title!: string
  public ownerId!: number
  public status!: string
  public cover?: string
  public notice?: string
  public onlineCount!: number
}

Room.init(
  {
    id: {
      type: DataTypes.INTEGER,
      autoIncrement: true,
      primaryKey: true,
    },
    title: {
      type: DataTypes.STRING(100),
      allowNull: false,
    },
    ownerId: {
      type: DataTypes.INTEGER,
      allowNull: false,
    },
    status: {
      type: DataTypes.ENUM('live', 'offline', 'banned'),
      defaultValue: 'offline',
    },
    cover: {
      type: DataTypes.STRING(200),
    },
    notice: {
      type: DataTypes.STRING(500),
    },
    onlineCount: {
      type: DataTypes.INTEGER,
      defaultValue: 0,
    },
  },
  {
    sequelize,
    tableName: 'rooms',
  }
)
